// console.log("toviews");
window.onload = function(e) {
    var cname = getCookie("cname");
    var userName = getCookie("userName");
    var userType = getCookie("userType");
    // 请求单个项目查看页面数据
    function toviewGetData() {
        // 获取当前URL
        var hash = self.location.hash; //哈希值只读取#之后的
        cname = getCookie("cname");
        var i = hash.indexOf("=");
        var Hsid = hash.substring(i + 1, hash.length); //哈希里面不加#读不出sid
        const checkoneData = {
            ak: "13128755602",
            msg: "请求单个项目查看页面数据",
            sid: Hsid,
            getType: "checkOne",
        };
        // 获取单项目查看数据
        var inputs, imgs, imgName, inputJpgNames, inputJpgName;
        Dres = {};
        var url = "checkone?sid=" + Hsid;
        try {
            $.post(url, checkoneData, function(res, status, err) {
                // console.log(res);
                if (res.code == 200) {
                    Dres = res.info[0];
                    inputs = $("input"); ///获取全部input
                    imgs = $("img"); //获取全部img元素
                    // var names = $(inputs).eq(1).prop();
                    for (i = 0; i < inputs.length; i++) {
                        //写出全部input values
                        var names = inputs[i].name || "";
                        // console.log(names);
                        var values = Dres[names] || "";
                        // console.log(values);
                        var inputName = "input[name='" + names + "']";
                        $(inputName).val(values);
                        // console.log(inputName);
                    }
                    for (k = 0; k < imgs.length; k++) {
                        //写出img
                        imgName = imgs[k].name;
                        inputJpgNames = $(".boxJpg"); //图片缓存input
                        // console.log(inputJpgNames);
                        inputJpgName = inputJpgNames[k].name || ""; //图片缓存oinpus属性name名
                        var values = Dres[inputJpgName] || "http://zhilai-baojia.oss-cn-shenzhen.aliyuncs.com/img/20220302142909.bmp";
                        var imgStr = "img[name='" + imgName + "']";
                        $(imgStr).attr("src", values); //写出img地址src值
                        // var inputName2 = "input[name='" + inputJpgName + "']"; //定位到图缓存input的Name
                        // $(inputName2).val(values); //attr("value", //往input图片缓存地址暂存图片地址
                        // console.log(imgName, imgStr, values)
                        var boxTypes = $(".boxType");
                        var boxTypeName = "boxType" + (k + 1);
                        // console.log(boxTypeName);
                        $(boxTypes[k]).attr("title", Dres[boxTypeName]); //为较长内容的柜型名称单元格填充提示titel
                    }

                    //==========添加附件==================
                    for (key = 1; key < 6; key++) {
                        var b = "fileCount" + key;
                        var fileUrl = Dres[b] || "";
                        // console.log(b, fileUrl);
                        if (fileUrl != "" && fileUrl != undefined) {
                            var Arr = fileUrl.split("/") || null;
                            //   console.log(Arr);
                            var fileName = Arr[Arr.length - 1]; //<button class="btn  btn-default  abtn">&Chi;</button>
                            var alinkStr = ` <a title="单击附件链接可以下载附件！" target="_blank" download href="${fileUrl}" aria-placeholder="附件链接" alt="附件链接" class="fujinaLink"><input type="text" name="fileCount${key}" value="${fileUrl}" class="hide" title="附件链接" placeholder="附件链接" alt="附件链接">点击下载->${fileName} </a>`;
                            $("#fileAdd").append(alinkStr);
                        }
                    }
                    $("#projectInfos").html(Dres.projectInfos || "");
                    $("#sid2").html(Dres.sid || "null");
                    $("#id2").html(Dres.ID || "null"); //写出SID
                    // console.log(inputs[1].name, inputs.length);
                    var UpdateTime = Dres.UpdateTime || moment().format("YYYY-MM-DD HH:mm:ss"); //设置审批章时间
                    $(".UpdateTime").html(UpdateTime);
                    Toast("getData:success", "success", 1000, 800);
                    scal(); //刷新计算
                    var auditing = Dres.status;
                    $("#sid2").html(Dres.sid);
                    // console.log("toviewGetData:", Dres, auditing);
                    var Approver = Dres["Approver"] || "审批领导";
                    // console.log(Approver)
                    $(".Approver").html(Approver);
                    if (auditing == "已审批") {
                        $(".auditing").show();
                        $("#auditing").hide();
                    } else if (auditing == "待审批") {
                        $(".auditing").hide();
                        $("#auditing").show();
                    }
                    // 将某些显示很长单元格内容添加到title里面提示
                    var titelToasts = $(".titelToast");
                    for (var key = 0; key < titelToasts.length; key++) {
                        // console.log(titelToasts)
                        var varTitel = $(titelToasts[key]).html();
                        $(titelToasts[key]).attr("title", varTitel);
                        // console.log(varTitel)
                    }
                } else if (res.code == 100) {
                    console.log(res.msg);
                    Toast(res.msg, "error", 2000, 800);
                    narn("error", res.msg, "错误提示");
                } else if (res.code == 101) {
                    console.log(res);
                    Toast(res.msg, "error", 2000, 800);
                    narn("error", res.msg, "错误提示");
                } else {
                    console.log(res.msg);
                    Toast(err, "error", 2000, 800);
                    narn("error", res.msg, "错误提示");
                }
            });
        } catch (error) {
            Toast(error, "error", 1000, 800);
        }
    }
    toviewGetData();

    // 计算报价数据   输入内容离开编辑框后事件监听   onpropertychange  click   MouseEvent  mouseleave
    function scal(e) {
        try {
            // 取全部柜型种类数据及计算种类数量boxType
            var boxType = $(".boxType"); //柜型集合获取
            var boxCount = $(".boxCount"); // 柜型及数量获取
            // 材料成本获取
            var PackMates = $(".PackMates"); //包材集合
            var devices = $(".devices"); //电控集合
            var Pcb = $(".Pcb"); //主板集合
            var fenmo = $(".fenmo"); //粉末集合
            var others = $(".others"); //其他
            var lock = $(".lock"); //电控锁集合
            var wujin = $(".wujin"); //五金
            var cable = $(".cable"); //线材
            var cableCost = $(".cableCost"); //材料合计成本
            var Price = $(".Price"); //报价单价
            var AFMWTC = $(".AFMWTC"); //不含税材料+人工成本
            var AFCMTC = $(".AFCMTC"); //含税材料+人工，获取当列柜型单台含税成本字符串
            var ArtificialCost = $(".ArtificialCost"); //人工+制造费
            var metals = $(".metals"); //钢材集合
            var GrossProfit = $(".GrossProfit"); //毛利额-单价
            var GPfM = $(".GPfM"); //获取各列计算毛利率集合
            var SalesComm = $(".SalesComm"); //销售提成
            var transportation = $(".transportation"); //
            var NetAmount = $(".NetAmount"); //获取
            var Handling = $(".Handling"); //获取搬运费集合
            var transportation = $(".transportation"); //运输物流
            var afterSales = $(".afterSales"); //获取售后维保费集合
            var proFitMargin = $(".proFitMargin"); //单列净利率集合
            var PriceTotal2 = $(".PriceTotal2");
            var TotalNet = $(".TotalNet"); //净利率润合计
            var costCombined = $(".costCombined");
            // 不含税材料成本总计数据及计算小计 cableCost   cableCostTotal
            var PackMatesTotal = 0;
            var deviceTotal = 0;
            var cableTotal = 0;
            var cableCostTotal = 0; //总材料成本容器
            var boxCountTotal = 0; //总柜子数量容器
            var AlMWTCostTotal = 0;
            var AFCMTC_Total = 0; //不含税总成本
            var ACMaT_Total = 0; //含税总成本
            var PriceTotal_2 = 0; //总报价
            var metalTotal = 0; //
            var TypeCount = 0; //种类合计容器
            var GrossProfitTotal = 0; //毛利总额容器
            var afterSalesTotal = 0; //售后维保费总容器
            var transportationTotal = 0; //物流运输费总计算容器
            var HandlingTotal = 0; //装卸总搬运费容器
            var SalesCommissionsTotal = 0; //销售提成总额
            var NetAmountTotal = 0; //利润总额容器
            var proFitMarginTotal = 0; //平均利率容器
            var PriceTotalTotal = 0; //总报价
            var TotalNetTotal = 0; //净利润合计
            var costCombinedTotal = 0; //总含税成本
            for (j = 0, len = AFMWTC.length; j < len; j++) {
                // 柜型种类合计  有计算金额时候才需要加parsefloat 及tofexid(2)
                if ($(boxType[j]).val() != "" && $(boxType[j]).val() != null) {
                    TypeCount++;
                } else {}
                $("input[name='TypeCount']").val(TypeCount); //写出柜子种类数值

                // 取柜子采购数量数据及小计计算boxCount;
                var Nmb_boxCount = $(boxCount[j]).val();
                if (Nmb_boxCount == "" || Nmb_boxCount == null) {
                    Nmb_boxCount = 0;
                    $(boxCount[j]).val(0);
                }

                boxCountTotal += parseInt(Nmb_boxCount);
                $("input[name='boxCountTotal']").val(boxCountTotal); //写出总柜子数量合计

                // 各列柜型材料不含税成本;
                var str_PackMates = $(PackMates[j]).val();
                if (str_PackMates == "" || str_PackMates == null) {
                    str_PackMates = 0;
                    $(PackMates[j]).val(0);
                }
                var number_PackMates = parseFloat(str_PackMates); //.toFixed(2);

                var str_devices = $(devices[j]).val();
                if (str_devices == "" || str_devices == null) {
                    str_devices = 0;
                    $(devices[j]).val(0);
                }
                var number_devices = parseFloat(str_devices); //.toFixed(2);

                var str_Pcb = $(Pcb[j]).val();
                if (str_Pcb == "" || str_Pcb == null) {
                    str_Pcb = 0;
                    $(Pcb[j]).val(0);
                }
                var number_Pcb = parseFloat(str_Pcb); //.toFixed(2);

                var str_fenmo = $(fenmo[j]).val();
                if (str_fenmo == "" || str_fenmo == null) {
                    str_fenmo = 0;
                    $(fenmo[j]).val(0);
                }
                var number_fenmo = parseFloat(str_fenmo); //.toFixed(2);

                var str_metals = $(metals[j]).val();
                if (str_metals == "" || str_metals == null) {
                    str_metals = 0;
                    $(metals[j]).val(0);
                }
                var number_metals = parseFloat(str_metals); //.toFixed(2);

                var str_others = $(others[j]).val();
                if (str_others == "" || str_others == null) {
                    str_others = 0;
                    $(others[j]).val(0);
                }
                var number_others = parseFloat(str_others); //.toFixed(2);

                var str_lock = $(lock[j]).val();
                if (str_lock == "" || str_lock == null) {
                    str_lock = 0;
                    $(lock[j]).val(0);
                }
                var number_lock = parseFloat(str_lock); //.toFixed(2);

                var str_wujin = $(wujin[j]).val();
                str_wujin = isStr(str_wujin);
                //   if (str_wujin == "" || str_wujin == null) {
                // str_wujin = 0;
                $(wujin[j]).val(str_wujin);
                //   }
                var number_wujin = parseFloat(str_wujin); //.toFixed(2)

                var str_cable = $(cable[j]).val();
                if (str_cable == "" || str_cable == null) {
                    str_cable = 0;
                    $(cable[j]).val(0);
                }
                var number_cable = parseFloat(str_cable); //.toFixed(2)

                //#***************#//   合计材料
                cableCostTotal = parseFloat(number_PackMates + number_devices + number_Pcb + number_fenmo + number_metals + number_others + number_lock + number_wujin + number_cable).toFixed(2);
                $(cableCost[j]).val(cableCostTotal); //写出单柜型不含税材料成本合计

                //获取当列柜型单台含税成本字符串
                //#***************#// var Number_rote = parseFloat(str_rote).toFixed(2);
                var str_box = $(boxCount[j]).val(); //获取该列柜子数量
                var number_box = parseInt(str_box); //柜子数据转整数
                var str_AFCMTC = $(AFCMTC[j]).val();

                //#***************#//计算单柜型列不含税材料成本;
                if ($(cableCost[j]).val() == "" || $(cableCost[j]).val() == 0) {
                    $(cableCost[j]).val(0);
                }
                var str_cableCost = $(cableCost[j]).val(); //获取该柜型材料成本
                if (isnUll(str_cableCost)) {
                    str_cableCost = 0;
                    $(cableCost[j]).val();
                }
                var number_cableCost = parseFloat(str_cableCost); //材料成本转整数

                //#***************#// 不含税成本处理
                var str_ArtificialCost = $(ArtificialCost[j]).val(); //获取人工成本
                if (str_ArtificialCost == "" || str_ArtificialCost == 0) {
                    str_ArtificialCost = 0;
                    $(ArtificialCost[j]).val(0);
                }
                var number_ArtificialCost = parseFloat(str_ArtificialCost);
                AlMWTCostTotal = parseFloat(number_cableCost + number_ArtificialCost).toFixed(2);
                $(AFMWTC[j]).val(AlMWTCostTotal); //写出各列不含税成本

                //#***************#// 含税人工&制造费&材料总成本单柜合计，小计计算 AFCMTC   ACMaT_Total;
                if ($(cableCost[j]).val() == "" || $(cableCost[j]).val() == null) {
                    $(cableCost[j]).val(0);
                }
                var str_cableCost = $(cableCost[j]).val(); //获取该柜型材料成本
                if (isnUll(str_cableCost)) {
                    str_cableCost = 0;
                }
                var number_cableCost = parseFloat(str_cableCost); //材料成本转整数
                if ($(ArtificialCost[j]).val() == "" || $(ArtificialCost[j]).val() == null) {
                    $(ArtificialCost[j]).val(0);
                }
                var str_ArtificialCost = $(ArtificialCost[j]).val(); //获取人工成本
                if (isnUll(str_ArtificialCost)) {
                    str_ArtificialCost = 0;
                }
                var number_ArtificialCost = parseFloat(str_ArtificialCost); //人工
                AFCMTC_Total = parseFloat(
                    number_cableCost * 1.13 + number_ArtificialCost //含税材料+人工
                ).toFixed(2);
                $(AFCMTC[j]).val(AFCMTC_Total); //写出各列含税成本

                //#***************#// 计算该柜型含税成本合计 // 计算全部柜型含税材料+人工成本X数量合计;
                if (str_AFCMTC == null || str_AFCMTC == "" || str_AFCMTC == NaN) {
                    str_AFCMTC = 0;
                }
                var number_AFCMTC = parseFloat(str_AFCMTC).toFixed(4); //获取不含税成本单列数据
                if (str_AFCMTC == "" || str_AFCMTC == null) {
                    str_AFCMTC = 0;
                }
                if (number_box == "" || number_box == null) {
                    number_box = 0;
                }
                var hscb = parseFloat(number_AFCMTC * number_box).toFixed(2); //含税成本*数量
                ACMaT_Total = FloatAdd(hscb, ACMaT_Total); //自相加
                $("input[name='ACMaT_Total']").val(ACMaT_Total); //单列循完后写出该行合计含税总成本

                // 含税+毛利对外报价计算 Price   PriceTotal;
                //#***************#//计算各列成本X毛利的含税单价报价;
                var str_rote = $("#rote").val(); //获取毛利率 直接获取数据
                var number_rote = toPoint(str_rote); //获取了毛利率数
                var price_bj = number_AFCMTC / (1 - number_rote); //毛利报价=浮点数含税材料+人工总成本/毛利率
                var price_bj = (number_cableCost * 1.13) / (1 - number_rote) + number_ArtificialCost; //毛利报价=浮点数含税材料成本/毛利率+人工
                var PriceTotal = price_bj.toFixed(2); //当前计算出的报价转成浮点数
                $(Price[j]).val(PriceTotal); //写出各列柜型的单台含税毛利报价

                //#***************# // 以下是合计单列报价X数量的+全部柜型的合计;
                var one_box_bj = parseFloat(PriceTotal * number_box).toFixed(2); //计算出单柜型单价X数量
                PriceTotal_2 = FloatAdd(one_box_bj, PriceTotal_2); //计算出每个柜型X数量的全部报价合计
                $("input[name='PriceTotal']").val(PriceTotal_2); //写出每个柜型报价X数量总报价

                //#***************#// 毛利额=毛利外报价-含税成本，总毛利小计计算 GrossProfit   GrossProfitTotal;
                var str_priceX = $(Price[j]).val(); //获取当前列毛利报价值
                if (str_priceX == "" || str_priceX == null || str_priceX == NaN) {
                    str_priceX = 0;
                }
                var str_AFCMTCX = $(AFCMTC[j]).val(); //获取当前列含税成本
                if (str_AFCMTCX == "" || str_AFCMTCX == null || str_AFCMTCX == NaN) {
                    str_AFCMTCX = 0;
                }
                var GrossProfit = FloatSub(PriceTotal, AFCMTC_Total); //含税毛利报价-减含税成本
                $(".GrossProfit").eq(j).val(GrossProfit); //写出毛利额

                //#***************#// 总毛利额计算;
                oneBox_Gpf = GrossProfit * number_box; //获取单柜型的全部毛利
                GrossProfitTotal = FloatAdd(oneBox_Gpf, GrossProfitTotal);
                $("input[name='GrossProfitTotal']").val(GrossProfitTotal); //写出毛利报价总额

                //#***************#// 单列核算毛利率计算;
                var float_gpfm = FloatSub(PriceTotal, number_AFCMTC);
                var rote_gpfm = parseFloat((float_gpfm * 100) / (PriceTotal * 100)).toFixed(6);
                var Percent_gpfm = (number_rote * 100).toFixed(2);
                // console.log((float_gpfm * 100) / (PriceTotal * 100), rote_gpfm, Percent_gpfm)
                $(GPfM[j]).val(Percent_gpfm);
                $("input[name='GrossProfitMarginTotal']").val(Percent_gpfm); //写出报价毛利率

                //#***************#// 售后维保费计算afterSales  afterSalesTotal
                var Server_rote = $("#Server_rote").val(); //获取服务费率
                if (Server_rote == "" || Server_rote == null) {
                    Server_rote = 0;
                }
                var flaot_server_rote = parseFloat(Server_rote).toFixed(2);
                var str_afterSalesRote = parseFloat(PriceTotal * flaot_server_rote).toFixed(2);
                var number_afterSalePrice = parseFloat(str_afterSalesRote / 100).toFixed(2);
                $(afterSales[j]).val(number_afterSalePrice);

                //#***************#//写出总售后维保费合计
                var number_total_afterSalePrice = number_afterSalePrice * number_box; //单列售后服务费X单列数量
                afterSalesTotal = FloatAdd(number_total_afterSalePrice, afterSalesTotal); //没列累加
                // console.log(number_afterSalePrice, number_total_afterSalePrice, afterSalesTotal, Nmb_boxCount, number_box);
                $("input[name='afterSalesTotal']").val(afterSalesTotal); //写出报价毛利率

                //#***************#//物流运输费计算transportation transportationTotal
                var str_transportation = $(transportation[j]).val(); //.toFixed(2);
                if (isnUll(str_transportation)) {
                    str_transportation = 0;
                    $(transportation[j]).val(0);
                }
                var str_transportation2 = parseFloat(str_transportation * number_box).toFixed(2);
                transportationTotal = FloatAdd(str_transportation2, transportationTotal);
                $("input[name='transportationTotal']").val(transportationTotal); //写出物流费合计

                //#***************#//装卸搬运费计算  Handling HandlingTotal
                var str_Handling = $(Handling[j]).val(); //.toFixed(2);
                if (isnUll(str_Handling)) {
                    str_Handling = 0;
                    $(Handling[j]).val(0);
                }
                var str_Handling2 = parseFloat(str_Handling * number_box).toFixed(2);
                HandlingTotal = FloatAdd(str_Handling2, HandlingTotal);
                $("input[name='HandlingTotal']").val(HandlingTotal); //写出物流费合计

                //#***************#// 销售提成计算报价额5%;SalesComm SalesCommissionsTotal
                var str_salesComm = (PriceTotal * 0.05).toFixed(2); //parseFloat
                $(SalesComm[j]).val(str_salesComm); //写出销售提成
                //#***************#// 计算销售提成总额
                var str_salesComm_n = parseFloat(str_salesComm * number_box).toFixed(2);
                SalesCommissionsTotal = FloatAdd(str_salesComm_n, SalesCommissionsTotal);
                $("input[name='SalesCommissionsTotal']").val(SalesCommissionsTotal); //写出物流费合计

                //#***************# // 净利润额=毛利额-物流运输-装卸-售后维保-提成; NetAmount NetAmountTotal
                var str_afterSales = $(afterSales[j]).val();
                var fla_NetAmount1 = FloatSub(GrossProfit, str_Handling);
                var fla_NetAmount2 = FloatSub(fla_NetAmount1, str_transportation);
                var fla_NetAmount3 = FloatSub(fla_NetAmount2, str_afterSales);
                var fla_NetAmount4 = FloatSub(fla_NetAmount3, str_salesComm);
                $(".NetAmount").eq(j).val(fla_NetAmount4); //写出单列净利润，

                //#***************#// 计算净利润总额NetAmount NetAmountTotal
                var str_NetAmount_n = parseFloat(fla_NetAmount4 * number_box).toFixed(2); //单利润X数量
                NetAmountTotal = FloatAdd(str_NetAmount_n, NetAmountTotal);
                // console.log(str_NetAmount_n, NetAmountTotal);
                $("input[name='NetAmountTotal']").val(NetAmountTotal); //写出净利润总额合计

                //#***************#//净利率   proFitMargin proFitMarginTotal
                var flaot_proFitMargin = parseFloat((fla_NetAmount4 / PriceTotal) * 100).toFixed(2); //净利润除以报价
                $(proFitMargin[j]).val(flaot_proFitMargin); //写出单列净利率

                //#***************#// 计算平均净利率
                proFitMarginTotal = FloatAdd(flaot_proFitMargin, proFitMarginTotal); //累加单柜型净利率
                // console.log("j2:", j, fla_NetAmount4, PriceTotal, flaot_proFitMargin);
                if (j >= proFitMargin.length - 1) {
                    var proFitMarginTotal_10 = parseFloat(proFitMarginTotal / 10).toFixed(2); //求平均数
                    $("input[name='proFitMarginTotal']").val(proFitMarginTotal_10); //写出净利润总额合计
                }

                //#***************#// 含税毛利报价X数量合计  PriceTotal  PriceTotalTotal
                var onebox_price_add = parseFloat(PriceTotal * number_box).toFixed(2);
                $(PriceTotal2[j]).val(onebox_price_add);
                PriceTotalTotal = FloatAdd(onebox_price_add, PriceTotalTotal);
                // console.log("onebox_price_add:", onebox_price_add, PriceTotal, PriceTotalTotal, number_box);
                if (j >= proFitMargin.length - 1) {
                    $("input[name='PriceTotalTotal']").val(PriceTotalTotal); //写出总含税报价合计
                }

                //#***************#// 净利润合计 TotalNet TotalNetTotal
                var str_TotalNet = parseFloat(fla_NetAmount4 * number_box).toFixed(2); //净利润X数量
                $(TotalNet[j]).val(str_TotalNet); //写出单列净利润
                TotalNetTotal = FloatAdd(str_TotalNet, TotalNetTotal);
                if (j >= proFitMargin.length - 1) {
                    $("input[name='TotalNetTotal']").val(TotalNetTotal); //写出总净利润合计
                }

                //#***************#//含税成本总计计算 costCombined  costCombinedTotal
                var one_costCombined_ride = parseFloat(AFCMTC_Total * number_box).toFixed(2);
                $(costCombined[j]).val(one_costCombined_ride);
                costCombinedTotal = FloatAdd(one_costCombined_ride, costCombinedTotal); //用上方计算单柜含税成本数据X柜型数量
                if (j >= proFitMargin.length - 1) {
                    $("input[name='costCombinedTotal']").val(costCombinedTotal); //写出总净利润合计
                }
            }

            function isnUll(str) {
                if (str.length <= 0 || str == null || isNaN(str) || str == undefined) {
                    return true;
                } else {
                    return false;
                }
            }

            // 技术服务费计算
            //#***************#// 软件成本工费计算 soft_cost_Price  soft_unit soft_cost_Price soft_cost_time
            var soft_cost_time = $("input[name='soft_cost_time']").val(); //获取软件成本工时
            if (isnUll(soft_cost_time)) {
                soft_cost_time = 0;
                $("input[name='soft_cost_time']").val(0);
            }
            var soft_unit = $("input[name='soft_unit']").val(); //获取单价
            if (isnUll(soft_unit)) {
                soft_unit = 0;
            }
            var soft_cost_Price = parseFloat(soft_cost_time * soft_unit).toFixed(2);
            $("input[name='soft_cost_Price']").val(soft_cost_Price);

            //#***************#// 软件含税报价计算
            var kaifa_Time = $("input[name='kaifa_Time']").val(); //获取开发工时
            if (isnUll(kaifa_Time)) {
                kaifa_Time = 0;
                $("input[name='kaifa_Time']").val(0);
            }
            var soft_Total = parseFloat(kaifa_Time * soft_unit).toFixed(2);
            $("input[name='soft_Total']").val(soft_Total);

            //#***************#// 软件报价毛利率计算  soft_GPM
            var soft_Cost_subb = FloatSub(soft_Total, soft_cost_Price);
            var soft_GPM = parseFloat((soft_Cost_subb / soft_Total) * 100).toFixed(2);
            $("input[name='soft_GPM']").val(soft_GPM);

            //#***************#// 柜子成本工费计算  box_unit box_desiner_time box_cost_time box_cost_Price box_BGM box_Total
            var box_cost_time = $("input[name='box_cost_time']").val(); //获取柜子成本工时
            if (isnUll(box_cost_time)) {
                box_cost_time = 0;
                $("input[name='box_cost_time']").val(0);
            }
            var box_unit = $("input[name='box_unit']").val(); //获取单价
            if (isnUll(box_unit)) {
                box_unit = 0;
                $("input[name='box_unit']").val(0);
            }
            var box_cost_Price = parseFloat(box_cost_time * box_unit).toFixed(2); //计算费用
            $("input[name='box_cost_Price']").val(box_cost_Price); //写出软件定制费报价

            //#***************#// 柜子定制设计含税报价计算
            var box_desiner_time = $("input[name='box_desiner_time']").val(); //获取开发工时
            if (isnUll(box_desiner_time)) {
                box_desiner_time = 0;
                $("input[name='box_desiner_time']").val(0);
            }
            var box_Total = parseFloat(box_desiner_time * box_unit).toFixed(2);
            $("input[name='box_Total']").val(box_Total); //写出柜型定制费报价

            //#***************#// 柜子定制费报价毛利率计算
            var box_Cost_subb = FloatSub(box_Total, box_cost_Price);
            var box_BGM = parseFloat((box_Cost_subb / box_Total) * 100).toFixed(2);
            $("input[name='box_BGM']").val(box_BGM); //写出柜子定制费报价毛利率

            //#***************#//#总报价计算 PriceTotal  ProjectTotalPrice soft_Total box_Total
            var priceAddsoftAddbox = FloatAdd(PriceTotalTotal, soft_Total);
            var ProjectTotalPrice = FloatAdd(priceAddsoftAddbox, box_Total);
            $("input[name='ProjectTotalPrice']").val(ProjectTotalPrice); //写出项目总含税报价
            // console.log(ProjectTotalPrice);
        } catch (error) {
            errFlag = true;
            console.log(error);
            Toast("数据错误~", "error", 1000, 600);
        } finally {
            // finallyCode - 无论 try / catch 结果如何都会执行的代码块\
            // Toast("刷新计算~", "success", 1000, 500);
        }
    }

    // 浮点数相加方法
    function FloatAdd(arg1, arg2) {
        var r1, r2, m;
        try {
            r1 = arg1.toString().split(".")[1].length;
        } catch (e) {
            r1 = 0;
        }
        try {
            r2 = arg2.toString().split(".")[1].length;
        } catch (e) {
            r2 = 0;
        }
        m = Math.pow(10, Math.max(r1, r2));
        var number_m = (arg1 * m + arg2 * m) / m;
        return parseFloat(number_m).toFixed(2);
        // return number_m;
    }

    // 浮点数相减方法
    // alert(FloatSub("9999.22", "5555.11"))
    function FloatSub(arg3, arg4) {
        var r11, r22, m2;
        try {
            r11 = arg3.toString().split(".")[1].length;
        } catch (e) {
            r11 = 0;
        }
        try {
            r22 = arg4.toString().split(".")[1].length;
        } catch (e) {
            r22 = 0;
        }
        m2 = Math.pow(10, Math.max(r11, r22));
        var number_m2 = (arg3 * m2 - arg4 * m2) / m2;
        return parseFloat(number_m2).toFixed(2);
        // return number_m;
    }

    // 百分数转小数
    function toPoint(str_percent) {
        var str_percent2 = str_percent.replace(".", "");
        str_percent2 = "0." + str_percent2;
        var Nub = parseFloat(str_percent2).toFixed(4);
        // console.log("毛利率:(%)", Nub);
        return Nub;
    }

    // 异常提示方法
    function tip() {
        if (errFlag == true) {
            Toast("数据错误~", "error", 1000, 600);
        } else {
            Toast("刷新计算~", "success", 1000, 500);
            errFlag = false;
        }
        // console.log(errFlag);
    }

    // input输入事件
    $("input").change(function(e) {
        var number_thisVal = parseFloat($(this).val());
        if (number_thisVal < 0) {
            $(this).val(0);
        }
    });

    // $("#addForm").bind("input mouseleave", function(e) {});
    $("#addForm").bind("input oninput", function(e) {
        scal(e);
    });
    $("body").on("change", "input", function(e) {
        scal(e);
    });
    // 当鼠标点击选择输入框时候清除输入框内容,同时设置小计计算内容，onchange事件无法替代
    $("#addForm").on("click", ".form-control", function() {
        $(this).val("");
    });

    // 限制品名和品号输入中文
    $(".boxSN").bind("input onpropertychange ", function(e) {
        var str = $(this).val();
        var str2 = str.replace(/[\u0391-\uFFE5]/gi, "");
        $(this).val(str2);
        // console.log(str2);
    });
    $(".size").bind("input onpropertychange ", function(e) {
        var str = $(this).val();
        var str2 = str.replace(/[\u0391-\uFFE5]/gi, "");
        $(this).val(str2);
        // console.log(str2);
    });

    //-----------------//阻止鼠标单击等事件------------------
    $("input").on("focus", function() {
        $(this).blur();
    });

    $("textarea").on("focus", function() {
        $(this).blur();
    });

    $("body") //阻止鼠标单击等事件
        .find("button")
        .each(function() {
            // $(this).off("click").attr("onclick", "");
            $(this).on("click", function(event) {
                event.preventDefault();
            });
        });

    var alliNPUT = $("input");
    // 给全部input添加禁用
    for (k = 0; k < alliNPUT.length; k++) {
        // console.log(alliNPUT[k]);
        var thisinput = alliNPUT[k];
        // $("input").addClass("disabledCss"); //仅读
        $(alliNPUT[k]).addClass("disabledCss");
        alliNPUT[k].setAttribute("disabled", "disabled");
        // alert(thisinput.);
    }

    // ifram内外不同处理top/ 查看页面top栏提u出按钮修改 toviewTitel
    var iframeNmae = (window.frameElement && window.frameElement.id) || "noIframe";
    if (self.frameElement && self.frameElement.tagName == "IFRAME" && window.frames.length != parent.frames.length && self != top) {
        //   alert("在iframe中");
        //   console.log("在iframe中");
        $(".logoutBtn").hide();
        $("#glyphicon-log-out").hide();
        $("#toviewTitel").hide();
        if (iframeNmae == "iframe") {
            $("#file2").remove();
            //   var disabledCssIputs = $(".disabledCss");
            var abtns = $("#fileAdd .abtn");
            $(abtns[1]).remove();
            //   console.log("sss", abtns);
        }
    } else {
        $(".logoutBtn").show();
        $("#glyphicon-log-out").show();
        //   console.log("不在iframe中");
    }

    // --------------------------------------------------------

    // -------------------审批方法--------------------------------//
    $("#auditing").on("click", function(e) {
        try {
            var close = window.parent.document.getElementById("close");
            // console.log(close)
            var clickPage = getCookie("clickPage") || 1;
            var hash = self.location.hash; //哈希值只读取#之后的
            var i = hash.indexOf("=");
            var Hsid = hash.substring(i + 1, hash.length); //哈希里面不加#读不出sid
            var url = "/auditing";
            var subData = {
                sid: Hsid,
                cname: cname,
            };
            $.post(url, subData, function(res, status, err) {
                // console.log(res)
                if (res.code == 200) {
                    new Promise(function(resolve, reject) {
                            setTimeout(function() {
                                // console.log('First');
                                Toast(res.msg, "success", 1000, 500);
                                resolve(res);
                            }, 1);
                        })
                        .then(function(res) {
                            return new Promise(function(resolve, reject) {
                                setTimeout(function() {
                                    // console.log("Second");
                                    $("#auditing").hide(1);
                                    window.parent.narn("success", "审批:" + res.msg, "提示");
                                    resolve();
                                }, 100);
                            });
                        })
                        .then(function(res) {
                            return new Promise(function(resolve, reject) {
                                setTimeout(function() {
                                    // console.log("Third");
                                    $(".Approver").html(cname);
                                    $(".auditing").show(10);
                                    resolve();
                                }, 100);
                            });
                        })
                        .then(function() {
                            setTimeout(function() {
                                // console.log("four");
                                $(close).click();
                                window.parent.loadData(clickPage, 10);
                            }, 100);
                        });
                } else if (res.code == 101 || res.code == 101) {
                    Toast(res.msg, "error", 500, 500);
                    window.parent.narn("error", "审批:" + res.msg, "提示");
                    layer.confirm(res.msg);
                    $(close).click();
                } else {
                    console.log(res, err, status);
                    window.parent.narn("warn", "审批:" + res.msg, "提示");
                    //    layer.confirm(res.msg);
                    //   $(close).click();
                    windowParnet(1000, "left");
                }
            });
        } catch (error) {
            Toast(error, "error", 500, 500);
            window.parent.narn("error", "审批:" + res.status, "提示");
            console.log(res, err, error);
        }
    });

    //封装一个处理表单序列化数据格式
    function formatData(array) {
        var data = {};
        //处理需要提交的数据
        $.each(array, function(index, item) {
            data[item.name] = item.value;
        });
        return data;
    }

    // 右下角弹窗提法方法-------------------------

    const arr = new Array(10000);
    for (let i = 0; i < 10000; i++) {
        arr[i] = i + 1;
    }
    arr.sort(() => Math.random() - 0.5);
    const target = arr.splice(0, 8500);
    var conut = Math.ceil(Math.random() * 1000);
    var timer = Math.ceil(Math.random() * target[conut]); // * conut;
    var timer2 = Math.ceil(Math.random() * conut) * conut;
    var timer3 = timer + Math.ceil(Math.random() * timer) * timer;
    new Promise(function() {
        setTimeout(function() {
            window.parent.narn2("log", "查看状态下不可编辑修改，如需修改自己的项目请选择修改方式进入", "小提示", 10005);
        }, timer);
        setTimeout(function() {
            window.parent.narn2("log", "按快捷键‘ESC’可快速关闭模态框", "使用小指南", 10006);
        }, timer2);
        setTimeout(function() {
            window.parent.narn2("log", "如果你的报价项目被审批,系统会及时给出通知提醒！", "学习Tips", 10007);
        }, timer3);
    });
};